package com.axonactive.yolo.dto;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.SimpleFormatter;

import com.axonactive.yolo.domain.Task;
import com.axonactive.yolo.domain.TaskUserId;

public class TaskDTO {
	public final String DELIMITER = "@";
	
	private int id;

	private int userId;
	
	private String taskId;

	private String name;

	private String typeOfTrip;

	private String fromCode;

	private String toCode;

	private String fromAirport;

	private String toAirport;

	private String fromCountry;

	private String toCountry;

	private Date departDate;

	private Date returnDate;

	private int flexibleDays;

	private double maxPrice;

	private String currencyCode;

	private int maxStops;

	private String airlines;

	private String airlineNames;

	private String cabinClass;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	public String getTaskId() {
		return taskId;
	}

	public void setTaskId(String taskId) {
		this.taskId = taskId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getTypeOfTrip() {
		return typeOfTrip;
	}

	public void setTypeOfTrip(String typeOfTrip) {
		this.typeOfTrip = typeOfTrip;
	}

	public Date getDepartDate() {
		return departDate;
	}

	public void setDepartDate(Date departDate) {
		this.departDate = departDate;
	}

	public Date getReturnDate() {
		return returnDate;
	}

	public void setReturnDate(Date returnDate) {
		this.returnDate = returnDate;
	}

	public int getFlexibleDays() {
		return flexibleDays;
	}

	public void setFlexibleDays(int flexibleDays) {
		this.flexibleDays = flexibleDays;
	}

	public double getMaxPrice() {
		return maxPrice;
	}

	public void setMaxPrice(double maxPrice) {
		this.maxPrice = maxPrice;
	}

	public int getMaxStops() {
		return maxStops;
	}

	public void setMaxStops(int maxStops) {
		this.maxStops = maxStops;
	}

	public String getAirlines() {
		return airlines;
	}

	public void setAirlines(String airlines) {
		this.airlines = airlines;
	}

	public String getFromCode() {
		return fromCode;
	}

	public void setFromCode(String fromCode) {
		this.fromCode = fromCode;
	}

	public String getToCode() {
		return toCode;
	}

	public void setToCode(String toCode) {
		this.toCode = toCode;
	}

	public String getCurrencyCode() {
		return currencyCode;
	}

	public void setCurrencyCode(String currencyCode) {
		this.currencyCode = currencyCode;
	}

	public String getFromAirport() {
		return fromAirport;
	}

	public void setFromAirport(String fromAirport) {
		this.fromAirport = fromAirport;
	}

	public String getToAirport() {
		return toAirport;
	}

	public void setToAirport(String toAirport) {
		this.toAirport = toAirport;
	}

	public String getFromCountry() {
		return fromCountry;
	}

	public void setFromCountry(String fromCountry) {
		this.fromCountry = fromCountry;
	}

	public String getToCountry() {
		return toCountry;
	}

	public void setToCountry(String toCountry) {
		this.toCountry = toCountry;
	}

	public String getAirlineNames() {
		return airlineNames;
	}

	public void setAirlineNames(String airlineNames) {
		this.airlineNames = airlineNames;
	}

	public String getCabinClass() {
		return cabinClass;
	}

	public void setCabinClass(String cabinClass) {
		this.cabinClass = cabinClass;
	}

	public static String makeTaskId(TaskDTO taskDTO) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // Set your date format
		
		String str = "";
		str = taskDTO.getTypeOfTrip() + taskDTO.getFromCode() + taskDTO.getToCode()
				+ sdf.format(taskDTO.getDepartDate());
		
		if (taskDTO.getTypeOfTrip().equals("roundTrip")) {
			str += sdf.format(taskDTO.getReturnDate());
		}
		
		str += taskDTO.getCabinClass();
		
		return str;
	}
	
	public Task getTask(TaskDTO taskDTO) {
		Task task = new Task();
		task.setTypeOfTrip(taskDTO.getTypeOfTrip());
		task.setFromCode(taskDTO.getFromCode());
		task.setToCode(taskDTO.getToCode());
		task.setFromAirport(taskDTO.getFromAirport());
		task.setToAirport(taskDTO.getToAirport());
		task.setFromCountry(taskDTO.getFromCountry());
		task.setToCountry(taskDTO.getToCountry());
		task.setDepartDate(taskDTO.getDepartDate());
		task.setReturnDate(taskDTO.getReturnDate());
		task.setCabinClass(taskDTO.getCabinClass());
		task.setAvailable("1");
		task.setId(taskDTO.getId());
		task.setTaskId(taskDTO.getTaskId());
		
		return task;
	}
	
	public TaskUserId getTaskUserId(TaskDTO taskDTO) {
		TaskUserId taskUserId = new TaskUserId();
		taskUserId.setUserId(taskDTO.getUserId());
		taskUserId.setFlexibleDays(taskDTO.getFlexibleDays());
		taskUserId.setMaxPrice(taskDTO.getMaxPrice());
		taskUserId.setCurrencyCode(taskDTO.getCurrencyCode());
		taskUserId.setMaxStops(taskDTO.getMaxStops());
		taskUserId.setAirlines(taskDTO.getAirlines());
		taskUserId.setId(taskDTO.getId());
		taskUserId.setTaskId(taskDTO.getTaskId());
		taskUserId.setName(taskDTO.getName());
		
		return taskUserId;
	}
	
	public TaskDTO getTaskDTO(Task task, TaskUserId taskUserId) {
		TaskDTO taskDTO = new TaskDTO();
		taskDTO.setName(taskUserId.getName());
		taskDTO.setTypeOfTrip(task.getTypeOfTrip());
		taskDTO.setFromCode(task.getFromCode());
		taskDTO.setToCode(task.getToCode());
		taskDTO.setFromAirport(task.getFromAirport());
		taskDTO.setToAirport(task.getToAirport());
		taskDTO.setFromCountry(task.getFromCountry());
		taskDTO.setToCountry(task.getToCountry());
		taskDTO.setDepartDate(task.getDepartDate());
		taskDTO.setReturnDate(task.getReturnDate());
		taskDTO.setCabinClass(task.getCabinClass());
		
		taskDTO.setUserId(taskUserId.getUserId());
		taskDTO.setFlexibleDays(taskUserId.getFlexibleDays());
		taskDTO.setMaxPrice(taskUserId.getMaxPrice());
		taskDTO.setCurrencyCode(taskUserId.getCurrencyCode());
		taskDTO.setMaxStops(taskUserId.getMaxStops());
		taskDTO.setAirlines(taskUserId.getAirlines());
		
		taskDTO.setTaskId(task.getTaskId());
		
		return taskDTO;
	}
}